import request from '@/utils/request'

const URL_PREFIX = '/sys/config'

const fetchList = function(queryParams) {
  return request({
    url: `${URL_PREFIX}/list?page=${queryParams.pageNum}&pageSize=${queryParams.pageSize}`,
    method: 'post',
    data: queryParams
  })
}

const fetch = function(id) {
  return request({
    url: `${URL_PREFIX}/${id}`,
    method: 'post'
  })
}

const getByCode = function(code) {
  return request({
    url: `${URL_PREFIX}/get/${code}`,
    method: 'post'
  })
}

const save = function(data) {
  if (data.id === undefined) {
    return request({
      url: `${URL_PREFIX}/create`,
      method: 'post',
      data: data
    })
  } else {
    return request({
      url: `${URL_PREFIX}/edit`,
      method: 'post',
      data: data
    })
  }
}

const remove = function(ids) {
  return request({
    url: `${URL_PREFIX}/remove`,
    method: 'post',
    data: { values: ids }
  })
}

export default {
  fetchList,
  fetch,
  getByCode,
  save,
  remove
}
